package com.example.gokchinesefoodmappcdev.service.impl;

import com.example.gokchinesefoodmappcdev.dao.GoodsSkuDao;
import com.example.gokchinesefoodmappcdev.entity.dto.GoodsDTO;
import com.example.gokchinesefoodmappcdev.entity.dto.GoodsInfoExcelDTO;
import com.example.gokchinesefoodmappcdev.service.GoodsSkuService;
import com.example.gokchinesefoodmappcdev.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsSkuServiceImpl implements GoodsSkuService {

    @Autowired
    GoodsSkuDao goodsSkuDao;


    @Override
    public ResultData updateSkuInfo(Integer id, Double price, Integer stock, String weight) {
        int i = goodsSkuDao.updateSkuInfo(id, price, stock, weight);
        if(i>0){
            return new ResultData(0,"操作成功!");
        }

        return new ResultData(500,"操作失败");
    }

    @Override
    public ResultData updateSkuPicByGoodIdAndPicPath(Integer goodId, String picPath) {
        int i = goodsSkuDao.updateSkuPicByGoodIdAndPicPath(goodId, picPath);
        if(i>0){
            return new ResultData(0,"操作成功!");
        }

        return new ResultData(500,"操作失败");
    }

    @Override
    public String selectPicPathByGoodId(Integer goodId) {

        String picPath = goodsSkuDao.selectPicPathByGoodId(goodId);
        return picPath;
    }

    @Override
    public ResultData insertSkuInfo(Integer goodId, GoodsDTO goodsInfo) {

        String attrSymbolPath = goodsInfo.getAttrSymbolPath();
        Double price = goodsInfo.getPrice();
        Integer sales = goodsInfo.getSales();
        Integer stock = goodsInfo.getStock();
        String weight = goodsInfo.getWeight();
        int i = goodsSkuDao.insertSkuInfo(goodId, attrSymbolPath,price,sales,stock,weight);
        if(i>0){
            return new ResultData(0,"操作成功!");
        }

        return new ResultData(500,"操作失败");
    }
}
